Namespacing everything to /UVa.
[andmenj-acm.git] / UVa / 11663 - GrayInc / 11663.2.cpp
blob361dcaa72d4d3410ae2b0383bdd6d3612c9be9de
1 using namespace std;
2 #include <algorithm>
3 #include <iostream>
4 #include <iterator>
5 #include <sstream>
6 #include <fstream>
7 #include <cassert>
8 #include <climits>
9 #include <cstdlib>
10 #include <cstring>
11 #include <string>
12 #include <cstdio>
13 #include <vector>
14 #include <cmath>
15 #include <queue>
16 #include <deque>
17 #include <stack>
18 #include <list>
19 #include <map>
20 #include <set>
22 template <class T> string toStr(const T &x){ stringstream s; s << x; return s.str(); }
23 template <class T> int toInt(const T &x){ stringstream s; s << x; int r; s >> r; return r; }
25 #define For(i, a, b) for (int i=(a); i<(b); ++i)
26 #define foreach(x, v) for (typeof (v).begin() x = (v).begin(); x != (v).end(); ++x)
27 #define D(x) cout << #x " = " << (x) << endl
29 int next(const string &s, int i);
30 int prev(const string &s, int i);
32 bool looksLike0000(const string &s, int i){
33 for (; i<s.size(); ++i) if (s[i] != '0') return false;
34 return true;
37 bool looksLike1000(const string &s, int i){
38 if (s[i] != '1') return false;
39 for (++i; i<s.size(); ++i) if (s[i] != '0') return false;
40 return true;
43 int next(const string &s, int i){
44 if (i == s.size() - 1) return i;
45 if (s[i] == '0'){
46 if (looksLike1000(s, i+1)){
47 return i;
48 }else{
49 return next(s, i+1);
51 }else{
52 if (looksLike0000(s, i+1)){
53 return i;
54 }else{
55 return prev(s, i+1);
60 int prev(const string &s, int i){
61 if (i == s.size() - 1) return i;
62 if (s[i] == '0'){
63 if (looksLike0000(s, i+1)){
64 return i;
65 }else{
66 return prev(s, i+1);
68 }else{
69 if (looksLike1000(s, i+1)){
70 return i;
71 }else{
72 return next(s, i+1);
77 int main(){
78 int m;
79 string s;
80 while (cin >> m >> s && m){
81 while (m--){
82 int where = next(s, 0);
83 s[where] = s[where] == '0' ? '1' : '0';
85 cout << s << endl;
87 return 0;